<template>
	<view>
		<nav-bar   fontColor="#FFFFFF" title="抢单"></nav-bar>
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>
		<v-tabs v-model="activeTab" @change="changeTb" :scroll="false" :bold="true" :tabs="tabs1" field="name"></v-tabs>
		<!-- <view v-if="tbStatus == 0"> -->
		<view>
			<!-- <view class="orderNumber">数量：{{total}}个</view> -->
			<mescroll-body v-if="tbStatus === 0" @init="mescrollInit" @down="downCallback" @up="dataListChoose">
				<view class="orderNumber">数量：{{total}}个</view>
				<view v-for="(item,index) in dataList">
					<uni-list>
						<uni-list-item @click="putawayInfo(item)" :index="index+1" :title="'物品名称:'+item.materialName "
							:note="'数量:'+item.qty + '\n'+ '时间:'+item.updateTime" rightText="查看" link="reLaunch"
							clickable>
						</uni-list-item>
					</uni-list>
				</view>
			</mescroll-body>
			<mescroll-body v-else @init="mescrollInit" @down="downCallback" @up="dataListChoose">
				<view class="orderNumber">数量：{{total2}}个</view>
				<view v-for="(item,index) in dataList2">
					<uni-list>
						<uni-list-item @click="pickInfo(item)"  :index="index+1" :title="'物品名称:'+item.materialName "
							:note="'数量:'+item.qty + '\n'+ '时间:'+item.updateTime" rightText="查看" link="reLaunch"
							clickable>
						</uni-list-item>
					</uni-list>
				</view>
			</mescroll-body>
		</view>
		<!-- 	<view v-else>
			<view class="orderNumber">数量：{{total2}}个</view>
			<mescroll-body @init="mescrollInit" @down="downCallback" @up="getDataList1">
				<view v-for="(item,index) in dataList1">
					<uni-list>
						<uni-list-item :index="index+1" :title="'物品名称:'+item.materialName "
							:note="'数量:'+item.qty + '\n'+ '时间:'+item.updateTime" rightText="查看" link="reLaunch"
							clickable>
						</uni-list-item>
					</uni-list>
				</view>
			</mescroll-body>
		</view> -->
		<!-- <view style="height: 60rpx;">
			<view class="bottomBox">
				<view class="buttonBox">
					<button class="button_fix" size="default">手动分配</button>
					<button class="button_fix" size="default">自动分配</button>
				</view>
			</view>
		</view> -->
		<uni-popup ref="message" type="message">
			<uni-popup-message :type="msgType" :message="messageText" :duration="3000"></uni-popup-message>
		</uni-popup>
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog :before-close="true" type="info" cancelText="回到首页" confirmText="继续绑卡" title="提示"
				content="还有其他物品需要继续绑卡吗？" @confirm="dialogConfirm()" @close="dialogClose()"></uni-popup-dialog>
		</uni-popup>
		<!-- 	<uni-popup ref="popup" @change="change">
			<view class="popup">
				<image src="../../static/img/status.png" mode=""></image>
				<view>请扫描RFID射频标签</view>
			</view>
		</uni-popup> -->

	</view>
</template>

<script>
	var main = null;
	var receiver = null;
	import uniList from '@/components/uni-list/uni-list.vue';
	import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		components: {
			uniList,
		},
		data() {
			return {
				msgType: 'success',
				messageText: '这是一条成功提示',
				Qrcode: '',
				orderNumber: "BC010302",
				activeTab: 0,
				tbStatus: 0,
				tabs1: [{
						name: '拣货任务',
						value: 1
					},
					{
						name: '上架任务',
						value: 2
					}
				],
				//搜索内容
				downOption: {
					native: false,
					use: true, // 是否启用下拉刷新; 默认true
					auto: true
				},
				upOption: {
					use: true, // 是否启用上拉加载; 默认true
					auto: false,
					noMoreSize: 5, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看
				},
				dataList: [],
				dataList2: [],
				total: null,
				total2: null,
				rfid: '',
				itemId: [], //存放每个案件id的数组
				status: true,
				rfidLength: 0,
				epc: ''
				// repeatRfid: [],//rfid重复数组
				// rfId: []//rfid数组无重复

			};
		},
		onLoad() {
			// this.startCheck();
			// this.getDataList();
			// this.get_gb();
		},
		onBackPress() {
			if (receiver != null) {
				main.unregisterReceiver(receiver)
			}
		},
		onShow() {
			this.mescroll.resetUpScroll();
		},
		//方法
		methods: {
			dataListChoose(e) {
				if (this.tbStatus == 0) {
					this.getDataList(e)
				} else {
					this.getDataList1(e)
				}
			},
			putawayInfo(e){
				let dataInfo = JSON.stringify(e)
				uni.navigateTo({
					url:'/pages/grap-order/grap-order-info-putaway?id='+dataInfo
				})
			},
			pickInfo(e){
				let dataInfo = JSON.stringify(e)
				uni.navigateTo({
					url:'/pages/grap-order/grap-order-info-pick?id='+dataInfo
				})
			},
			dialogConfirm() {
				this.$refs.alertDialog.close();
			},
			dialogClose() {
				this.$refs.alertDialog.close();
				uni.navigateBack({
					delta: 1
				});
			},
			changeTb(e) {
				this.tbStatus = e;
				console.log(e)
				this.mescroll.resetUpScroll();
			},
			messageToggle(type, msg) {
				this.msgType = type
				this.messageText = msg
				this.$refs.message.open();
			},
			get_gb() {
				var that = this;
				main = plus.android.runtimeMainActivity();
				receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
					onReceive: function(context, intent) {
						plus.android.importClass(intent);
						var data = intent.getExtra("data");
						if (data) {
							console.log(data)
							that.rfid = data
							that.rfidLength = 1;
							// that.repeatRfid.push(data)
							// for (let i = 0; i < that.repeatRfid.length; i++) {
							// 	if (that.rfId.indexOf(that.repeatRfid[i]) == -1) {
							// 		that.rfId.push(that.repeatRfid[i])
							// 		console.log(that.rfId)
							// 	}
							// }
						}
					}
				});
				var IntentFilter = plus.android.importClass('android.content.IntentFilter');
				let filter = new IntentFilter();
				filter.addAction('android.rfid.epccode');
				var info = main.registerReceiver(receiver, filter)
				// main.unregisterReceiver(receiver)
			},
			goBindCard(e) {
				// this.rfid = '';
				// this.epc = '';
				// this.itemId = [];
				// this.itemId.push(e)
				// console.log(this.itemId)
				// this.getRfid();
				// this.status = !this.status
				// this.$refs.popup.open()
				let shippingData = JSON.stringify(e)
				console.log(shippingData)
				uni.navigateTo({
					url: '/pages/shipping-order/shipping-order-info?id=' + shippingData
				})
			},

			getDataList(page) {
				let that = this;
				let opt = {
					url: 'web/tWmsReciptIntoLocPlan/search/' + page.num + '/10',
					method: 'POST'
				};
				let params = {
					status: "published",
					// jobType: "recept",
					id: uni.getStorageSync('userInfo').id,
					jobUserNo: '任务发布'
				};
				that.$http.httpTokenRequest(opt, params).then(res => {
					if (res.data.code == 200) {
						this.mescroll.endByPage(res.data.data.records.length, res.data.data
							.total); //必传参数(当前页的数据个数, 总页数)
						this.total = res.data.data.total
						if (page.num == 1) {
							this.dataList = res.data.data.records;
						} else {
							this.dataList = this.dataList.concat(res.data.data.records);
						}
						if (res.data.data.records == '') {
							// this.messageToggle('error', '暂无数据')
						}
						uni.hideLoading()
					} else {
						uni.hideLoading()
						this.messageToggle('error', res.data.msg)
					}
				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
			getDataList1(page) {
				let that = this;
				let opt = {
					url: 'web/tWmsDeliveryPickupPlan/search/' + page.num + '/10',
					method: 'POST'
				};
				let params = {
					status: "published",
					// jobType: "recept",
					pickUpUserNo: '任务发布'
				};
				that.$http.httpTokenRequest(opt, params).then(res => {
					if (res.data.code == 200) {
						that.mescroll.endByPage(res.data.data.records.length, res.data.data
							.total); //必传参数(当前页的数据个数, 总页数)
						that.total2 = res.data.data.total
						if (page.num == 1) {
							that.dataList2 = res.data.data.records;

						} else {
							that.dataList2 = that.dataList2.concat(res.data.data.records);
						}
						if (res.data.data.records == '') {
							// this.messageToggle('error', '暂无数据')
						}
						uni.hideLoading()
					} else {
						uni.hideLoading()
						that.messageToggle('error', res.data.msg)
					}
				}).catch(() => {
					//联网失败, 结束加载
					that.mescroll.endErr();
				})
			},
			// getDataList(page) {
			// 	console.log(page)
			// 	let opt = {
			// 		url: 'web/tbWmsMaterialDeliveryLine/search/' + page.num + '/10',
			// 		method: 'POST'
			// 	};
			// 	this.$http.httpTokenRequest(opt, {}).then(res => {
			// 		if (res.data.code == 200) {
			// 			this.mescroll.endByPage(res.data.data.records.length, res.data.data.total); //必传参数(当前页的数据个数, 总页数)
			// 			this.total = res.data.data.total
			// 			if (page.num == 1) {
			// 				this.dataList = res.data.data.records;
			// 			} else {
			// 				this.dataList = this.dataList.concat(res.data.data.records);
			// 			}
			// 			if (res.data.data.records == '') {
			// 				this.messageToggle('error', '暂无数据')
			// 			}
			// 			uni.hideLoading()
			// 		} else {
			// 			uni.hideLoading()
			// 			this.messageToggle('error', res.data.msg)
			// 		}

			// 	}).catch(() => {
			// 		//联网失败, 结束加载
			// 		this.mescroll.endErr();
			// 	})
			// },

			onPageJump(url) {
				uni.navigateTo({
					url: url
				});
			},
		},
		//页面下来刷新
		onPullDownRefresh() {
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 2000);
		}
	};
</script>
<style lang="scss" scoped>
	page {
		background: #FFFFFF;
	}

	.popup {
		width: 100%;

		view {
			font-size: 35rpx;
			color: #FFFFFF;
			margin-top: 50rpx;
			text-align: center;
			letter-spacing: 3rpx;
			font-weight: 700;
		}

		image {
			display: block;
			margin: 0 auto;
		}
	}

	.end-title {
		display: flex;
		border-bottom: 1px solid #E5E5E5;
	}

	.end-title view {
		flex-grow: 1;
		text-align: center;
		background: #FFFFFF;
		// border-top: 1px solid #E5E5E5;
	}

	.btna {

		border-bottom: 2px solid #007AFF;
		color: #007AFF;
	}

	.tab {
		padding: 30rpx;
		font-size: 35rpx;
	}

	.mapStyle {
		height: 1200rpx;
		width: 100%;
		margin-top: 10rpx;
	}

	/*说明*/
	.orderNumber {
		text-align: center;
		padding: 30rpx;
		font-size: 30rpx;
		letter-spacing: 3rpx;
		font-weight: 700;
		// font-family: '宋体';
		// font-weight: ;
	}

	.imgCode {
		position: relative;
		background: linear-gradient(#000000, #000000) left top,
			linear-gradient(#000000, #000000) left top,
			linear-gradient(#000000, #000000) right top,
			linear-gradient(#000000, #000000) right top,
			linear-gradient(#000000, #000000) right bottom,
			linear-gradient(#000000, #000000) right bottom,
			linear-gradient(#000000, #000000) left bottom,
			linear-gradient(#000000, #000000) left bottom;
		background-repeat: no-repeat;
		background-size: 2px 20px, 20px 2px;
		height: 400rpx;
		width: 400rpx;
		margin: 0 auto;
		margin-top: 35%;
	}

	.txtTop {
		margin-top: 50rpx;
	}

	.qrImg {
		width: 250rpx;
		height: 250rpx;
		left: 20%;
		top: 15%;
	}

	.bottomBox {
		position: fixed;
		width: 100%;
		bottom: 0;
		margin-bottom: 20rpx;
		z-index: 1000;
	}

	.buttonBox {
		width: 70%;
		margin: 0 auto;
		display: flex;
		justify-content: space-around;

		// margin-top: 200rpx;
	}

	.button_fix {
		width: 40%;
		height: 70rpx;
		// margin: 0 auto;
		color: #FFFFFF;
		background: #2749C8;
		font-weight: bold;
		letter-spacing: 5rpx;
		font-size: 28rpx;
		line-height: 70rpx;

	}
</style>